package com.mall.b2c.controller;

import javax.annotation.Resource;

import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;

import com.mall.b2c.domain.delivery.DeliveryCenterDomain;
import com.mall.b2c.domain.delivery.DeliveryTemplateDomain;
import com.mall.b2c.service.DeliveryCenterService;
import com.mall.b2c.service.DeliveryTemplateService;
import com.mall.b2c.service.OrderService;
import com.mall.common.controller.BaseController;

/**
 * 打印
 * 
 * @author lzx
 *
 */
@Controller
@RequestMapping("/admin/b2c/print")
public class PrintController extends BaseController {
	
	@Resource private OrderService orderService;
	@Resource private DeliveryTemplateService deliverTemplateService;
	@Resource private DeliveryCenterService deliverCenterService;
	
	@RequestMapping(value = "/delivery", method = RequestMethod.GET)
	public String delivery(Long orderId, Long deliveryTemplateId,
			Long deliveryCenterId, ModelMap model) {
		DeliveryTemplateDomain localDeliveryTemplate = (DeliveryTemplateDomain) deliverTemplateService
				.find(deliveryTemplateId);
		DeliveryCenterDomain localDeliveryCenter = (DeliveryCenterDomain) deliverCenterService
				.find(deliveryCenterId);
		if (localDeliveryTemplate == null) {
			localDeliveryTemplate = deliverTemplateService.findDefault();
		}
		if (localDeliveryCenter == null) {
			localDeliveryCenter = deliverCenterService.findDefault();
		}
		model.addAttribute("deliveryTemplates", deliverTemplateService.getAll());
		model.addAttribute("deliveryCenters", deliverCenterService.getAll());
		model.addAttribute("order", orderService.find(orderId));
		model.addAttribute("deliveryTemplate", localDeliveryTemplate);
		model.addAttribute("deliveryCenter", localDeliveryCenter);
		return "/admin/b2c/print/delivery";
	}
}
